/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.options.bank.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.options.bank.entity.ToptionsBank;
import com.jeesite.modules.zx.options.bank.service.ToptionsBankService;

/**
 * 选项库Controller
 * @author zpp
 * @version 2020-03-27
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/options/bank/toptionsBank")
public class ToptionsBankController extends BaseController {

	@Autowired
	private ToptionsBankService toptionsBankService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ToptionsBank get(String id, boolean isNewRecord) {
		return toptionsBankService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:view")
	@RequestMapping(value = {"list", ""})
	public String list(ToptionsBank toptionsBank, Model model) {
		model.addAttribute("toptionsBank", toptionsBank);
		return "modules/zx/options/bank/toptionsBankList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ToptionsBank> listData(ToptionsBank toptionsBank, HttpServletRequest request, HttpServletResponse response) {
		toptionsBank.setPage(new Page<>(request, response));
		Page<ToptionsBank> page = toptionsBankService.findPage(toptionsBank);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:view")
	@RequestMapping(value = "form")
	public String form(ToptionsBank toptionsBank, Model model) {
		model.addAttribute("toptionsBank", toptionsBank);
		return "modules/zx/options/bank/toptionsBankForm";
	}

	/**
	 * 保存选项库
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ToptionsBank toptionsBank) {
		toptionsBankService.save(toptionsBank);
		return renderResult(Global.TRUE, text("保存选项库成功！"));
	}
	
	/**
	 * 停用选项库
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(ToptionsBank toptionsBank) {
		toptionsBank.setStatus(ToptionsBank.STATUS_DISABLE);
		toptionsBankService.updateStatus(toptionsBank);
		return renderResult(Global.TRUE, text("停用选项库成功"));
	}
	
	/**
	 * 启用选项库
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ToptionsBank toptionsBank) {
		toptionsBank.setStatus(ToptionsBank.STATUS_NORMAL);
		toptionsBankService.updateStatus(toptionsBank);
		return renderResult(Global.TRUE, text("启用选项库成功"));
	}
	
	/**
	 * 删除选项库
	 */
	@RequiresPermissions("zx:options:bank:toptionsBank:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ToptionsBank toptionsBank) {
		toptionsBankService.delete(toptionsBank);
		return renderResult(Global.TRUE, text("删除选项库成功！"));
	}
	
}